package com.zdxlz.fcmp.common.mqtt.handler;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttCallback;
import org.eclipse.paho.mqttv5.client.MqttDisconnectResponse;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;

/**
 * @author: aman
 * @date 2025/2/11 11:29
 * @description
 */

@Slf4j
public abstract class BaseMqttCallbackHandler implements MqttCallback {

    @Override
    public void disconnected(MqttDisconnectResponse mqttDisconnectResponse) {
        log.info("【MQTT】断开连接，断开原因；{}", mqttDisconnectResponse.getReasonString());
    }

    @Override
    public void mqttErrorOccurred(MqttException e) {
        log.error("【MQTT】错误信息码：{}，错误信息：{}", e.getReasonCode(), e.getMessage());
    }

    @Override
    public void deliveryComplete(IMqttToken iMqttToken) {
        log.info("【MQTT】消息成功发送到服务器后被调用的回调函数触发：{}", iMqttToken.isComplete());
    }

    @Override
    public void connectComplete(boolean reconnect, String serverURI) {
        log.info("【MQTT】连接成功，broker 地址：{}", serverURI);
    }

    @Override
    public void authPacketArrived(int reasonCode, MqttProperties properties) {
        log.info("【MQTT】认证包到达，reasonCode: {}, MqttProperties: {}", reasonCode, properties);
    }
}
